package net.killerscape.skills;

/*
 * @author James Munnelly
 *
 */
import net.killerscape.model.Player;
import net.killerscape.model.SkillLevel;

import java.util.Arrays;

public class Prayer {
	private Player player;
	private boolean[] prayersEnable = new boolean[LEVEL_REQ.length];
	public int[] headIconPrayers = {14,13,12,15,17,16};
	
	public Prayer(Player p) {
		Arrays.fill(prayersEnable, false);
		player = p;
	}
	
	public int getHeadicon() {
		if(prayersEnable[PRAY_PROTECTMAG] && prayersEnable[PRAY_PROTECTMIS])
			return 6;
		for(int i = 0; i < prayersEnable.length; i++) {
			if(prayersEnable[i]) {
				return headIcon[i];
			}
		}
		return -1;
	}
	
	public void disablePrayer(int prayer) {
		if(isHeadiconPrayer(prayer)) {
			if(prayersEnable[prayer]) {
				prayersEnable[prayer] = false;
				player.getActionSender().setButtonState(prayer+83,false);
			}
		} else {
			prayersEnable[prayer] = false;
			player.getActionSender().setButtonState(prayer+83,false);
		}
	}
	
	public boolean isHeadiconPrayer(int prayer) {
		for(int i = 0; i < headIconPrayers.length; i++)
			if(prayer == headIconPrayers[i])
				return true;
		return false;
	}
	
	public boolean isUsingHeadiconPrayer() {
		if(getHeadicon() != -1)
			return true;
		return false;
	}
	
	public void togglePrayer(int id) {
		if(isHeadiconPrayer(id)) {
			if(id != PRAY_PROTECTMAG && prayersEnable[PRAY_PROTECTMIS] && id != PRAY_PROTECTMIS)
				disablePrayer(PRAY_PROTECTMIS);
			if(id != PRAY_PROTECTMIS && prayersEnable[PRAY_PROTECTMAG] && id != PRAY_PROTECTMAG)
				disablePrayer(PRAY_PROTECTMAG);
			if(id != PRAY_PROTECTMELEE)
				disablePrayer(PRAY_PROTECTMELEE);
			if(id != PRAY_SMITE)
				disablePrayer(PRAY_SMITE);
			if(id != PRAY_RETRIBUTION)
				disablePrayer(PRAY_RETRIBUTION);
			if(id != PRAY_REDEMPTION);
				disablePrayer(PRAY_REDEMPTION);
		}

		prayersEnable[id] = !prayersEnable[id];
		player.appearanceUpdateRequired();
	}
	
	public void activatePrayer(int id) {
		if(player.getSkillLevel().getSkillLevel(SkillLevel.PRAYER) >= LEVEL_REQ[id])
            if(player.getSkillLevel().getCurrentLevel(SkillLevel.PRAYER) > 0)
                switch(id) {
                case PRAY_PROTECTMAG:
                    togglePrayer(PRAY_PROTECTMAG);
                    break;
                case PRAY_PROTECTMELEE:
                    togglePrayer(PRAY_PROTECTMELEE);
                    break;
                case PRAY_PROTECTMIS:
                    togglePrayer(PRAY_PROTECTMIS);
                    break;
                case PRAY_SMITE:
                    togglePrayer(PRAY_SMITE);
                    break;
                case PRAY_RETRIBUTION:
                    togglePrayer(PRAY_RETRIBUTION);
                    break;
                case PRAY_RAPIDHEAL:
                    togglePrayer(PRAY_RAPIDHEAL);
                    player.getSkillLevel().setRestoreRate(prayersEnable[id] ? 30 : 60, SkillLevel.HITPOINTS);
                    break;
                case PRAY_RAPIDRESTORE:
                    togglePrayer(PRAY_RAPIDRESTORE);
                    break;
                }
            else
                disablePrayer(id);
        else {
			player.getActionSender().sendMessage("You need a prayer level of "+LEVEL_REQ[id]+" to use "+PRAYER_NAME[id]+".");
			disablePrayer(id);
		}
	}
	
	private int[] headIcon = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,1,0,3,5,4};
	private static final int[] LEVEL_REQ = {1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52};
	private static final int PRAY_THICKSKIN = 0,
							 PRAY_BURSTSTR = 1,
							 PRAY_CLARITY = 2,
							 PRAY_ROCKSKIN = 3,
							 PRAY_SUPERSTRENGTH = 4,
							 PRAY_IMPROVED = 5,
							 PRAY_RAPIDRESTORE = 6,
							 PRAY_RAPIDHEAL = 7,
							 PRAY_PROTECT = 8,
							 PRAY_STEELSKIN = 9,
							 PRAY_ULTIMATESTR = 10,
							 PRAY_INCREDIBLEREFLEX = 11,
							 PRAY_PROTECTMAG = 12,
							 PRAY_PROTECTMIS = 13,
							 PRAY_PROTECTMELEE = 14,
							 PRAY_RETRIBUTION = 15,
							 PRAY_REDEMPTION = 16,
							 PRAY_SMITE = 17;
    
	private static final String[] PRAYER_NAME = {"Thick Skin",
												"Burst of Strength",
												"Clarity of Thought",
												"Rock Skin",
												"Superhuman Strength",
												"Improved Reflexes",
												"Rapid Restore",
												"Rapid Heal",
												"Protect Items",
												"Steel Skin",
												"Ultimate Strength",
												"Incredible Reflexes",
												"Protect from Magic",
												"Protect from Missiles",
												"Protect from Melee",
												"Retribution",
												"Redemption",
												"Smite"};	
}
